<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Document</title>
  <style>
    .box{
      width: 400px;
      height: 300px;
      border: 1px solid red;
      margin: 40px auto;
    }
    .title{
      width: 100%;
      height: 50px;
      border-bottom: 1px solid #ccc;
    }
    .title span{
      display: block;
      float: left;
      width: 33.3%;
      text-align: center;
      line-height: 50px;
    }
    .active{
      background: orange;
      color: white;
    }
  
    li{
      list-style: none;
      margin: 50px auto;
      padding: 0 60px;
    }
    a{
      display: block;
      text-decoration: none;
      margin: 10px auto;
    }
  </style>
</head>
<body>
  <div class="box">
    <div class="title">
      <span class="active" data-name="c">促销</span>
      <span data-name="g">公告</span>
      <span data-name="d">更多</span>
    </div>
    <div class="content">
      <ul>
        <li style="display: none" id='c' >
          <a href="">家纺自营满199减100</a>
          <a href="">200元优惠券限量抢！</a>
          <a href="">智能家电领券100减50</a>
        </li>
        <li style="display: none" id = 'd'>
          <a href="">京东全球售升级 新域名同</a>
          <a href="">京东全球售升级 新域名同</a>
          <a href="">东大件物流“送装一体</a>
        </li>
        <li  style="display: block" id='g'>
          <a href="">TCL空调制暖季 2017-10-17</a>
          <a href="">TCL空调制暖季 2017-10-17</a>
          <a href="">TCL空调制暖季 2017-10-17</a>
        </li>
      </ul>
    </div>
  </div>
  <script>
    var span = document.querySelectorAll('span');
    var li = document.querySelectorAll('li');
    console.log(li);
    for(var i = 0; i < span.length; i++){
      span[i].onclick = function(){
        for(var j = 0; j < span.length; j++){
          span[j].className = '';
       }
        this.className = 'active';
        var ids = this.dataset.name 
        var id_dom = document.getElementById(ids)
        for(var k = 0; k < li.length; k++){
          li[k].style.display = 'none';
        }  
        id_dom.style.display = 'block';

      }
    }

  </script>
</body>
</html>